﻿using System;
using System.Collections.Generic;
using System.Web;
using RN.ERP.Web.PersonService;
using Newtonsoft.Json;
using RN.ERP.Web.ModelService;

namespace RN.ERP.Web.Exam
{
    public partial class KCZCList : BasePage
    {
        #region Params

        PersonServiceClient client = new PersonServiceClient();
        private string CurPageCode = "ZC";
        private string CurPage = "KCZCList.aspx";
        private string AppID
        {
            get
            {
                return HttpContext.Current.Application[ApplicationConstant.APPLICATION_ID].ToString();
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ////考场ID
                string kcIDStr = Request.QueryString["kcid"];
                int kcID = 0;
                if (int.TryParse(kcIDStr, out kcID))
                {
                    BindKCInfo(kcID);
                    BindData();
                }                
            }
        }

        private void BindKCInfo(int id)
        {
            string rst = client.GetExamKC(id);
            Exam_Room room = JsonConvert.DeserializeObject<Exam_Room>(rst);
            if (room != null)
            {
                lblKCName.Text = room.Title;
                lblKCCode.Text = room.Code;
                string[] addr = room.ExamAddress.Split('|');
                lblKCAddr.Text = addr[1];
            }
        }

        private void BindData()
        {
            int kcid = 0;
            int.TryParse(Request.QueryString["kcid"], out kcid);
            int count = 0;
            ////获取该考场下的座次安排
            var list = client.GetKCZCList(CurPageCode, UserInfo.RoleId, CurPage, AppID, kcid, UserInfo.CorpUserGuid, 0, 0, out count);
            if (list != null)
            {
                rptEmp.DataSource = JsonConvert.DeserializeObject<List<ExamEmpRoom>>(list);
                rptEmp.DataBind();
            }
        }

        public string GetImgUrl(object fileName)
        {
            return string.Format("../Handlers/GetFileHandler.ashx?fileName={0}&sysCode=EFNoWater&funcCode={2}&rand ={3}", fileName + ".jpg", hidSys.Value, hidFunc.Value, Guid.NewGuid());
        }
    }
}